package com.kpx.app.adapter;

import java.util.ArrayList;
import java.util.List;

import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

/**
 * viewpager的适配器
 * 
 * @Description TODO
 * @author chencong
 * @date 2015年1月10日
 * @Copyright: Copyright (c) 2015 Shenzhen Tentinet Technology Co., Ltd. Inc. All rights reserved.
 */
public class MyPagerAdapter extends PagerAdapter {

	private ArrayList<String> menuBeas = new ArrayList<>();
	/** 装有内容页面的list */
	public List<View> mListViews;

	public MyPagerAdapter(List<View> mListViews, ArrayList<String> menuBeas) {
		this.mListViews = mListViews;// 接受list
		this.menuBeas = menuBeas;// 接受list
	}
	public MyPagerAdapter(List<View> mListViews) {
		this.mListViews = mListViews;// 接受list
	}

	@Override
	public void destroyItem(View arg0, int arg1, Object arg2) {
		((ViewPager) arg0).removeView(mListViews.get(arg1));// 移除不需要的页面
	}

	@Override
	public void finishUpdate(View arg0) {
	}

	@Override
	public int getCount() {
		return mListViews.size();// 页面的数量
	}

	@Override
	public Object instantiateItem(View arg0, int arg1) {
		((ViewPager) arg0).addView(mListViews.get(arg1), 0);// 添加页面
		return mListViews.get(arg1);
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == (arg1);
	}

	@Override
	public void restoreState(Parcelable arg0, ClassLoader arg1) {
	}

	@Override
	public Parcelable saveState() {
		return null;
	}

	@Override
	public void startUpdate(View arg0) {
	}
	public CharSequence getPageTitle(int position) {
		return menuBeas==null?"":menuBeas.get(position);
	}

	public ArrayList<String> getTitles() {
		return menuBeas;
	}
}
